exports.__esModule = true;

var _fs = require("fs");

var _fs2 = _interopRequireDefault(_fs);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
  constructor(ctx) {
    super(ctx);
    this.MenuService = think.service("sys/MenuService");
  }
  indexAction() {}

  /**
   * 获取自定义表单图片
   *
   * @returns
   */
  appReadCustomTemplateAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      let aj = think.ajaxJson();
      let serverIP = "http://" + think.config("staticIp") + ":" + think.config("port"); //开发环境
      const isDev = think.env === "development"; //是否开发环境，true开发环境
      if (!isDev) {
        //生产环境
        serverIP = "http://" + think.config("staticIp") + ":" + think.config("proxyPort");
      }
      let url = "./www/static/upload/customTemplate/";
      let imgPath = "/static/upload/customTemplate/";
      let a = _fs2.default.readdirSync(url);
      let res = [];
      let obj = {};
      for (let i = 0; i < a.length; i++) {
        obj.img = imgPath + a[i];
        obj.showing = false;
        res.push(obj);
        obj = {};
      }
      aj.success = true;
      aj.msg = "获取成功";
      aj.result = res;
      return _this.json(aj);
    })();
  }
  //保存文件
  saveFileAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      let aj = think.ajaxJson();
      let fileDate = _this2.post();
      const file = _this2.file("file");
      console.log("105105", file);
      // if (file) {
      //   let file_path = await this.renameFile(file);
      //   if (file_path) {
      //     fileDate.realpath = file_path.filePathStatic;
      //   } else {
      //     aj.success = false;
      //     aj.msg = "文件保存失败";
      //     return this.json(aj);
      //   }
      // }
      let result = {};

      if (!result.error) {
        aj.result = fileDate.realpath;
      } else {
        aj.success = false;
        aj.msg = "保存错误";
        return _this2.json(aj);
      }
      return _this2.json(aj);
    })();
  }
};